package com.weixin.paleituo.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.weixin.paleituo.R;
import com.weixin.paleituo.bean.SumBrokerageBean;
import com.weixin.paleituo.util.UIUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 我的佣金界面数据Adapter
 *
 * @author fengzhen
 * @version v1.0, 2018/5/11
 */
public class SumBrokerageRecyclerAdapter extends RecyclerView.Adapter {
    private List<SumBrokerageBean.ListBean> mData;

    public SumBrokerageRecyclerAdapter(List<SumBrokerageBean.ListBean> data) {
        this.mData = data;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = UIUtils.inflate(parent.getContext(), R.layout.item_brokerage, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        SumBrokerageBean.ListBean bean = mData.get(position);
        if (position == 0) {
            viewHolder.mTvTypeItemBrokerage.setVisibility(View.VISIBLE);
            viewHolder.mTvTypeItemBrokerage.setText("总佣金记录:");
        } else {
            viewHolder.mTvTypeItemBrokerage.setVisibility(View.GONE);
        }
        viewHolder.mTvDateItemBrokerage.setText(bean.getUpdateTime().split(" ")[0]);
        viewHolder.mTvNumItemBrokerage.setText(bean.getMoneyString());
    }

    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_type_item_brokerage)
        TextView mTvTypeItemBrokerage;
        @BindView(R.id.tv_num_item_brokerage)
        TextView mTvNumItemBrokerage;
        @BindView(R.id.tv_date_item_brokerage)
        TextView mTvDateItemBrokerage;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
